package com.lbmb.photodrawaimanager.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lbmb.photodrawaimanager.entity.dto.PhotoVideoSaveEntity;
import com.lbmb.photodrawaimanager.entity.req.PhotoVideoCensusReq;
import com.lbmb.photodrawaimanager.entity.req.PhotoVideoSaveReq;
import com.lbmb.photodrawaimanager.mapper.PhotoVideoSaveUserMapper;
import com.lbmb.photodrawaimanager.service.PhotoVideoCensusService;
import com.lbmb.photodrawaimanager.service.PhotoVideoSaveUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author hanWang
 * @Title:
 * @Package
 * @Description:
 * @date 2023/8/34:48 上午
 */
@Service
public class PhotoVideoSaveUserServiceImpl extends ServiceImpl<PhotoVideoSaveUserMapper, PhotoVideoSaveEntity> implements PhotoVideoSaveUserService
{
    @Autowired
    private PhotoVideoSaveUserMapper photoVideoSaveUserMapper;
    @Autowired
    private PhotoVideoCensusService photoVideoCensusService;
    @Override
    public Boolean saveVideo(PhotoVideoSaveReq req) {
        Long userId = 100L;
        PhotoVideoSaveEntity photoVideoSaveEntity = new PhotoVideoSaveEntity();
        BeanUtils.copyProperties(req,photoVideoSaveEntity);
        int insert = photoVideoSaveUserMapper.insert(photoVideoSaveEntity);
        photoVideoSaveEntity.setUserId(userId);
        if (req.getSourceUser()==null){
            // 默认为 官方推广获得 不分成
            photoVideoSaveEntity.setSourceUser(1L);
        }else {
            // 如果是有用户分成 则存入分成表
            PhotoVideoCensusReq photoVideoCensusReq = new PhotoVideoCensusReq();
            photoVideoCensusReq.setUserId(req.getSourceUser());
            photoVideoCensusReq.setAgentUserId(userId);
            photoVideoCensusReq.setVideoId(req.getVideoId());
            photoVideoCensusReq.setCommission(req.getCommission());
            Boolean flag = photoVideoCensusService.saveCensus(photoVideoCensusReq);
            return insert>1&&flag;

        }
        return insert>1;
    }
}
